<?php

/**
 * @author      Alex Bilbie <hello@alexbilbie.com>
 * @copyright   Copyright (c) Alex Bilbie
 * @license     http://mit-license.org/
 *
 * @link        https://github.com/thephpleague/oauth2-server
 */

declare(strict_types=1);

namespace app\index\Repositories;

use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\UserEntityInterface;
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
use app\index\Entities\UserEntity;

// class UserRepository implements UserRepositoryInterface
// {
//     /**
//      * {@inheritdoc}
//      */
//     public function getUserEntityByUserCredentials(
//         $username,
//         $password,
//         $grantType,
//         ClientEntityInterface $clientEntity
//     ): ?UserEntityInterface {
//         if ($username === 'alex' && $password === 'whisky') {
//             return new UserEntity();
//         }

//         return null;
//     }
// }

class UserRepository implements UserRepositoryInterface
{
    /**
     * @return UserEntityInterface
     */
    public function getUserEntityByUserCredentials(
        $username,
        $password,
        $grantType,
        ClientEntityInterface $clientEntity
    ) {
        // 验证用户时调用此方法
        // 用于验证用户信息是否符合
        // 可以验证是否为用户可使用的授权类型($grantType)与客户端($clientEntity)
        // 验证成功返回 UserEntityInterface 对象
        $user = new UserEntity(1);
        // $user->setIdentifier(1);

        return $user;
    }
}
